<div id="wrapMain">
            <div class="wrap_1024" style="margin-bottom:40px">

            <div class='head_nav'><span class="icon-picture"></span> Get story chapters</div>
            <div class="user_profile">
				
				<div class="row" >
					<div class="col-md-12 ">
						<div id="contentIndex" class="col-md-12">
										<div role="dialog" id="modalAlertBox" class="modal fade" style="display: none;">
											<div class="modal-dialog modal-wide">
												<div class="modal-content">
													<div class="modal-header">
														<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
														<h4 class="modal-title"></h4>
													</div>
											        <div class="modal-body">
														
														<div style="clear:both"></div>
											        </div>
												</div><!-- /.modal-content -->
											</div>
										</div>
										
										<div id="wrapLoadMoreItems">
											<div class="normalLoadBtn" id="loadMoreItems"><img width="20" alt="loading" src="public/images/loading.gif"> Loading </div><br>
										</div>
										<div class="formLoading"></div>
										
									    <div class="generalError" style="display: none;"></div>
									    <form id="videoUpload" class="userPostForm" role="form" method="post" enctype="multipart/form-data">
											
											 <div class="form-group">
												<div class="row">
                                                <div class="col-md-2">
												<label for="txtStory">Story</label>
                                                </div>
                                                <div class="col-md-10">
													<select id="txtStory" class="select2" style="width:50%;">
														<?php 
														if($data['stories']):
														
														foreach($data['stories'] as $value):
														?>
														<option value="<?= $value['id']; ?>"><?= $value['ten']; ?></option>	
														
														<?php
														endforeach;
														endif;
														?>
														
													</select>
												</div>
												
                                                </div>
                                            </div>
										
											<br />
                               
                                           
                                                
                                            <div class="row"> <!-- Start class row wrap upload image and submit button -->
                                            <div class="col-md-2">
                                            </div>
                                            <div class="col-md-10">
											<button type="submit" class="btn btn-primary mySubmit" id="submitStoryChapters">
							                    <i class="glyphicon glyphicon-hand-up"></i>
							                    <span>Đăng bài</span>
							                </button>
                                            </div> <!-- End of class col-md-10 wrap upload image and submit button -->
                                            </div><!-- End of class row wrap upload image and submit button -->
											
										</form>
				
						</div><!-- end #contentIndex -->
					</div>
					
					
				</div> <!-- End of row -->
			</div><!-- end wrap_1024 -->
		</div><!-- end wrapMain -->
		
<!-- end #wrapMain -->		
		

<script type="text/javascript">
	$(document).ready(function(){
		
		
	    $('.createAlbum').click(function(e){
		    e.preventDefault();
		    $('#txtAlbum_message').remove();
		    $('#modalAlbumBox').remove();
		    var that = this;
			$.ajax({
				url : "<?php echo BASE_URL ?>index.php?module=user&act=ajax&albumBox=1",
				success : function(data){
					$('.createAlbum').parent().append(data);
					$('.createAlbum').parent().find('#modalAlbumBox').modal();
				},
			});
		});

	    $('#txtTitle').blur(function(){
	    	$.ajax({
	    		url: "index.php?module=user&act=ajax&validateTitle=1",
	    		type: 'POST',
	    		data: {txtTitle: $('#txtTitle').val()},
	    		success: function(data){
	    			newData = $.parseJSON(data);
	    			if(newData.errors){
		    			
		    			if($('#txtTitle_error').length <= 0){
			    		
		    				$('#txtTitle').parent().append('<div id="txtTitle_error" class="alert alert-danger alert-dismissable" style="display: none;"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>'+newData.errors.txtTitle+'</div>');
		    				$('#txtTitle_error').slideDown('fast');
		    			}else{
							$('#txtTitle_error').html(newData.errors.txtTitle);
		    			}
	    				
	    			}else{
	    				$('#txtTitle_error').remove();
	    			}
	    		}
	    	});
	    });

	    $('#txtDescription').blur(function(){
	    	//$(this).parent().find('.alert').remove();
	    	$.ajax({
	    		url: "index.php?module=user&act=ajax&validateDescription=1",
	    		type: 'POST',
	    		data: {txtDescription: $('#txtDescription').val()},
	    		success: function(data){
	    			newData = $.parseJSON(data);
	    			console.log(newData);
	    			if(newData.errors.txtDescription){
	    				if($('#txtDescription_error').length <= 0){
		    				$('#txtDescription').parent().append('<div id="txtDescription_error" class="alert alert-danger alert-dismissable" style="display: none;"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>'+newData.errors.txtDescription+'</div>');
		    				$('#txtDescription_error').slideDown('fast');
	    				}else{
							$('#txtDescription_error').html(newData.errors.txtDescription);
		    			}
	    			}else{
	    				$('#txtDescription_error').remove();
	    			}
	    		}
	    	});
	    });

	    /*
	     * Submit event
	     */
	    $('button#submitStoryChapters').click(function(e){
	    	e.preventDefault();
	    	$(".alert").remove();
	  		$('.userPostForm').css('opacity', '0.3');
			$('.formLoading')
			.css('width', $('#videoUpload').width())
			.css('height', $('#videoUpload').height())
			.css('opacity', '1')
			.css('z-index','9999').css('display', 'block');
			$('#wrapLoadMoreItems').css('display', 'block').center();

	    	$.ajax({
	    		url : "<?php echo BASE_URL; ?>index.php?module=user&act=ajax&submitStoryChapters=1",
	    		type : 'POST',
	    		cache: false,
	    		data: {story_id:$('#txtStory').val()},
	    		success : function(data){	
		    		alert('here');
	    			$('#wrapLoadMoreItems').css('display', 'none');
		    		if(data){
						returnData = $.parseJSON(data);
						console.log(returnData);
						if(returnData.error){
							popupMessage('Lỗi', [newData.error], 'alert-danger');
							if(returnData.fail_chapers){
								$.each(returnData.fail_chapers, function(i1, index1){
									console.log(index1);
								});
							}
						}
		    		}
		    	}
	    	});
		    	
    		
	    });

	   	function getChaptersViaPage(newData){
		   	
		   	startPage = newData.startPage;
	   		newurl = newData.url.replace('%s%', startPage);
	   		
	   		returnSend = false;
	   		
	   		$.ajax({
				url: "<?php echo HOME; ?>index.php?module=user&act=ajax&validateGetChapter=1",
				type: 'POST',
				cache: false,
				//dataType: 'jsonp',
				async: false,
				timeout: 800000,
				data: {txtSource: $('#txtSource').val(), txtSourceUrl: newurl},
				success: function(data1){
					console.log(data1);
					if(data1 != 'het'){
						
						//console.log('here if khac false - ' + data1);
						if(data1) returnData = $.parseJSON(data1);
						
						
						
					}else{
						//console.log('here returnSend true');
						returnSend = true;
						return false;
					}
					
				},

				error: function(x, t, m) {
			        if(t==="timeout") {
			            alert("got timeout");
			        } else {
				        console.log(x);
				        console.log(t);
				        console.log(m);
			        	
			        }
			    },
				
				complete: function(jqXHR, textStatus){
					
					if(returnSend == true){
						console.log('returnSend ' + returnSend);
						return;
					}

					newData.startPage = newData.startPage + 1;
					getChaptersViaPage(newData);
				}
			});
	   	}
	    
	    $('.select2').select2({ width: '250' });
		$('#txtSource').select2({width: '150'});
	});
</script>

<script src="public/exts/js/jquery.center.js"></script>
